package com.qg.log.event;

import com.qg.log.entity.OptLogDTO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;

import java.util.function.Consumer;

/**
 * @Author QG
 * @Date 2023/5/30 14:49
 * @description 日志事件监听器
 **/
@Slf4j
public class SysLogLister {

    private Consumer<OptLogDTO> consumer;

    public SysLogLister(Consumer<OptLogDTO> consumer) {
        this.consumer = consumer;
    }

    @Async
    @Order
    @EventListener(SysLogEvent.class)
    public void saveSysLog(SysLogEvent sysLogEvent) {
        OptLogDTO optLogDTO  = (OptLogDTO) sysLogEvent.getSource();
        consumer.accept(optLogDTO);
    }
}
